对main 未定义的引用_错误:ID返回1个退出状态(对“ main”的未定义引用)

对main 未定义的引用

As we know that,

我们知道

  1. Each program must have a main() function, compiler starts execution from the main() function - main() is an entry point to the program,

    每个程序必须具有main()函数,编译器从main()函数开始执行-main()是程序的入口点,

  2. And, the second this "C language is a case-sensitive language - uppercase words, and lowercase words are different".

    并且,第二种是“ C语言是区分大小写的语言-大写单词和小写单词不同”

This error is occurred on following cases,

在以下情况下会发生此错误,

  1. If main() is not written in lowercase, like you used Main(), MAIN(), mAin() or anything else.

    如果main()不是用小写字母编写的,就像您使用Main() , MAIN() , mAin()或其他任何东西一样。

  2. If main() does not exist in the program or by mistake you mistyped the main().

    如果程序中不存在main()或错误地键入了main() 。

Consider the programs...

考虑程序...

Program 1) 'main()' is not in lowercase

程序1)'main()'不是小写

#include <stdio.h>

int Main(void) {
	printf("Hello world!");
	return 0;
}

Output

输出量

/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

Program 2) Mistyped 'main()' as 'nain()' or anything else

程序2)将'main()'输入为'nain()'或其他任何东西

#include <stdio.h>

int nain(void) {
	printf("Hello world!");
	return 0;
}

Output

输出量

/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

How to fix?

怎么修?

To fix this error - use correct syntax of main() i.e. use main(), type correct spelling in lowercase

要解决此错误-使用main()的正确语法,即使用main() ,用小写字母输入正确的拼写

Correct code:

正确的代码:

#include <stdio.h>

int main(void) {
	printf("Hello world!");
	return 0;
}

Output

输出量

Hello world!


翻译自: https://www.includehelp.com/c-programs/id-returned-1-exit-status-undefined-reference-to-main-error-in-c.aspx

对main 未定义的引用

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值